<template>
  <el-dialog :title="title" :visible.sync="$parent.openDig" width="60%">
    <el-table v-if="title === '记录异常'" :data="tableList" style="width: 100%">
      <el-table-column prop="faultDescribe" label="故障描述" min-width="280" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="faultHandleDescribe" label="异常处理描述" min-width="280" show-overflow-tooltip>

      </el-table-column>
      <el-table-column label="处理人" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.handleUser }}
        </template>
      </el-table-column>
      <el-table-column label="处理时间" min-width="160">
        <template slot-scope="scope">
          {{ scope.row.handleTime }}
        </template>
      </el-table-column>
    </el-table>
    <el-table v-else :data="tableList" style="width: 100%">
      <el-table-column prop="faultDescribe" label="故障描述" min-width="280" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="faultHandleDescribe" label="异常处理描述" min-width="280" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-input v-model="scope.row.faultHandleDescribe" placeholder="异常处理描述"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="处理人" min-width="130">
        <template slot-scope="scope">
          <el-select v-model="scope.row.handleUserId" style="width:100%" placeholder="请选择处理人">
            <el-option v-for="value in userList" :key="value.userId" :label="value.userName" :value="value.userId">
            </el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="处理时间" min-width="160">
        <template slot-scope="scope">
          <el-date-picker style="width:100%" v-model="scope.row.handleTime" type="date" placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
          </el-date-picker>
        </template>
      </el-table-column>
    </el-table>

    <div slot="footer" align="center">
      <el-button type="primary" v-if="title !== '记录异常'" @click="submitForm">确 定</el-button>
      <el-button @click="$parent.openDig = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { Updaterecord } from "@/api/record/index.js";
import { listUser } from "@/api/system/user.js";
export default {
  props: ['title', 'rowObj'],
  data () {
    return {
      userList: [],
      tableList: []
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      const queryuser = {
        status: '0'//正常
      }
      let { data: user } = await listUser(queryuser)
      this.userList = user
      this.tableList = JSON.parse(JSON.stringify(this.rowObj.inspectionPlaceRecordAbnormalList))
    },
    submitForm () {
      let params = {
        id: this.rowObj.id,
        inspectionPlaceRecordAbnormalList: this.tableList
      }
      Updaterecord(params).then(res => {
        if (res.code == 200) {
          this.$parent.openDig = false
          this.$parent.getList()
        }
      }).catch(err => {
        console.log(err);
      })
    }
  }
}
</script>

<style>

</style>